using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sedna.Core.Controller.Configurations;

namespace Sedna.Core.Controls.Template
{
    public class ItemIndexColumnTemplate : ItemColumnTemplate
    {
        public ItemIndexColumnTemplate(DataGrid dataGrid, 
                                       IDataGridColumnConfiguration columnConfiguration)
            :base(dataGrid, columnConfiguration)
		{
		}


        protected override void BindLabel(object sender, EventArgs args)
        {
            System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)sender;
            DataGridItem dataGridItem = (DataGridItem)label.NamingContainer;

            int value = !dataGrid.AllowPaging ? dataGridItem.ItemIndex + 1: 
                        dataGrid.CurrentPageIndex * dataGrid.PageSize + dataGridItem.ItemIndex + 1;
            label.Text = value.ToString();
            label.Enabled = columnConfiguration.IsEnabledForPrincipal();
        }

        protected override void BindControl(object sender, EventArgs args)
        {
            BindLabel(sender, args);
        }
    }
}
